//	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------
///	@file	<CScreen9.h>
///	@path	~/src/graphics/dx9/
///	@date	2007/10/19
///	@desc	.

#pragma once

#include "xeres.h"

#include "graphics/IScreen.h"
#include "graphics/dx9/CDevice9.h"

namespace xeres {

	/*!
		\class	CScreen9
		\brief
	*/
	class CScreen9 : public IScreen
	{
	public:

		/// \ctor
		CScreen9( void );

		/// \dtor
		virtual ~CScreen9( void );

		DECL_IOBJECT_CLASS( CScreen9 , IScreen );

	public:

	//@ interface

		/*!
			\brief		Initialize screen for window.
		*/
		virtual bool Initialize( void * window , RefWeak<IDevice> device );

		/*!
			\brief		Finalize screen.
		*/
		virtual void Finalize( void );

		/*!
			\brief		Get associated window handle.
		*/
		virtual void * GetWindow( void );

		/*!
			\brief		Get screen size.
		*/
		virtual void GetSize( int& width , int& height );

		/*!
			\brief		Call when window size maybe changed.
		*/
		virtual void OnSize( bool minimized );

		/*!
			\brief		Call when window moved, may change monitor.
		*/
		virtual void OnMoved( void );

		/*!
			\brief		Call before render this screen.
		*/
		virtual bool BeginRender( void );

		/*!
			\brief		Call after render and ready to present the screen.
		*/
		virtual void EndRender( void );

	private:

		// check for size change
		void CheckForSizeChange( void );

		// update back buffer desc
		void UpdateBackBufferDesc( void );

	//@ data

		// window handle
		HWND						m_hWnd;
		
		// device
		Ref<CDevice9>				m_device;

		// swap chain
		IDirect3DSwapChain9 *		m_swapChain;

		// present parameters
		D3DPRESENT_PARAMETERS		m_presentParameters;

		// back buffer desc
		D3DSURFACE_DESC				m_backBufferSurfaceDesc;

		// states
		bool						m_ignoreSizeChange;		// Set to make size change call ignored
		bool						m_noUpdate;				// screen cannot be updated
		bool						m_releasingSwapChain;
		bool						m_minimized;
	};

} // namespace xeres
